// $('.right-titleicon').on("click", function(e) {
// 	projectVM.showMenulist()
// })

projectVM = new Vue({
	el: "#content",
	components: {
		personselect,
		processlog
	},
	data: {
		showAdd: false,
		id: '',
		menuList: [{
			name: '交班',
			path: 'handOver.html'
		}, {
			name: '接班',
			path: 'carryOn.html'
		}, {
			name: '列表',
			path: 'index.html'
		}, ],
		phenomenonTxt: '',
		fileIdsTraining: '',
		fileIds: '',
		userInfo: '',
		isSingle: true,
		trainId: '',
		drillInfo: [],
		filesList: [],
		trainingfileList: [],
		drill: {},
		drillTest:"p",
		trainingDrill: {},
		phenomenon: [],
		changeValue: '',
		checked: [],
		showSubmit: false,
		onStatus: '',
		result: '',
		showMenu: false,
		showMorebtn: false,
		abc: '1111',
		activityAttachIds: [],
		advance: '',
		id: '',
		workStatus: '',
		nextWorkStatus: '',
		show_popup: false,
		mData:{},
		list: [{
				content: 'XXX信用XXXX钥匙',
				status: 1,
				user: '[IP123456]张三2021-6-20'
			},
			{
				content: 'XXX信用XXXX钥匙',
				status: 2,
				user: '[IP123456]张三2021-6-20'
			},
			{
				content: 'XXX信用XXXX钥匙',
				status: 3,
				user: '[IP123456]张三2021-6-20'
			}
		]
	},
	mounted: function() {
		mui.init()

		this.id = JSON.parse(localStorage.getItem('neiosGoDetail')).obj.regularWorkTaskConfigId
		this.workId = JSON.parse(localStorage.getItem('neiosGoDetail')).obj.workId
		this.workStatus = JSON.parse(localStorage.getItem('neiosGoDetail')).obj.workStatus
		this.nextWorkStatus = JSON.parse(localStorage.getItem('neiosGoDetail')).obj.nextWorkStatus
		this.userInfo = JSON.parse(localStorage.getItem("neiosUser"))
		this.getDate()

	},
	methods: {
		//回显操作人
		changePerson() {
			if(null != this.drill.reviewStaffName){
			this.$refs.personselect_join.personids = this.drill.staffCode
			this.$refs.personselect_join.person = this.allName(this.drill.staffCode, this.drill.staffName)

			this.$refs.personselect_jianhu.personids = this.drill.tutelageStaffCode
			this.$refs.personselect_jianhu.person = this.allName(this.drill.tutelageStaffCode, this.drill
				.tutelageStaffName)
			this.$refs.personselect.personids = this.drill.reviewStaffCode
			this.$refs.personselect.person = '[' + this.drill.reviewStaffCode + ']' + this.drill.reviewStaffName

			}
			if(null != this.drillInfo.problemStaffCode){
				this.$refs.personselect_find.personids = this.drillInfo.problemStaffCode
				this.$refs.personselect_find.person = this.allName(this.drillInfo.problemStaffCode, this.drillInfo
					.problemStaffName)
				this.$refs.personselect_person.personids = this.drillInfo.appraiseStaffCode
				this.$refs.personselect_person.person = this.allName(this.drillInfo.appraiseStaffCode, this
					.drillInfo.appraiseStaffName)
				this.$refs.personselect_deal.personids = this.drillInfo.processStaffCode
				this.$refs.personselect_deal.person = '[' + this.drillInfo.processStaffCode + ']' + this.drillInfo
					.processStaffName
				this.$refs.personselect_current.personids = this.drillInfo.stepsStaffCode
				this.$refs.personselect_current.person = '[' + this.drillInfo.stepsStaffCode + ']' + this.drillInfo
					.stepsStaffName
			}


		},
		//获取多人员姓名
		filterNanme(e) {
			var arr = e.split(',')
			var list = []
			arr.forEach(item => {
				list.push(item.split(']')[1])
			})
			return list.join(',')
		},
		//合并多人员名称
		allName(e, f) {
			if (e == null || e == '' || f == null || f == '') {
				return ''
			}
			var a = e.split(',')
			var b = f.split(',')
			var c = []
			for (var i = 0; i < a.length; i++) {
				c.push('[' + a[i] + ']' + b[i])
			}
			return c.join(',')
		},

		//提交
		submit(param) {
			// console.log(JSON.stringify(e))
			mui.neiosRequst.httpRequst('/app/tranEducation/submitDrill', param,
				function(data) {
					mui.toast('操作成功')
					let page = plus.webview.getWebviewById(
					"../sitOperation/terminalwork/terminalwork.html");
					let pageId = plus.webview.getWebviewById(page.id);
					let param = {}
					param.isRefresh = true
					mui.fire(pageId, 'isRefresh', param);
					setTimeout(function() {
						mui.back()
					}, 500);
				},
				function() {
					console.log("查询失败!");
				}
			);

		},
		//保存
		save(e) {

			if (e == 'submit') {
				if (this.$refs.personselect_join.personids == '') {
					mui.toast('请选择参加人员')
					return
				} else if (this.$refs.personselect.personids == '') {
					mui.toast('请选择审核人员')
					return
				} else if (this.$refs.personselect_deal.personids == '') {
					mui.toast('请选择处理经过录入人')
					return
				} else if (this.$refs.personselect_current.personids == '') {
					mui.toast('请选择正确处理步骤录入人')
					return
				} else if (this.$refs.personselect_find.personids == '') {
					mui.toast('请选择发现问题及采取措施录入人')
					return
				} else if (this.$refs.personselect_person.personids == '') {
					mui.toast('请选择发现个人评价录入人')
					return
				} else if (this.$refs.personselect_jianhu.personids == '') {
					mui.toast('请选择监护人')
					return
				}

			}
			this.drill.staffCode = this.$refs.personselect_join.personids
			this.drill.staffName = this.filterNanme(this.$refs.personselect_join.person)
			this.drill.reviewStaffCode = this.$refs.personselect.personids
			this.drill.reviewStaffName = this.$refs.personselect.person.split(']')[1]
			this.drillInfo.processStaffCode = this.$refs.personselect_deal.personids
			this.drillInfo.processStaffName = this.$refs.personselect_deal.person.split(']')[1]
			// this.drillInfo.processStaffCodeName=this.$refs.personselect_deal.person
			this.drillInfo.stepsStaffCode = this.$refs.personselect_current.personids
			this.drillInfo.stepsStaffName = this.$refs.personselect_current.person.split(']')[1]
			this.drillInfo.problemStaffCode = this.$refs.personselect_find.personids
			this.drillInfo.problemStaffName = this.filterNanme(this.$refs.personselect_find.person)
			this.drillInfo.appraiseStaffCode = this.$refs.personselect_person.personids
			this.drillInfo.appraiseStaffName = this.filterNanme(this.$refs.personselect_person.person)
			this.drill.tutelageStaffCode = this.$refs.personselect_jianhu.personids
			this.drill.tutelageStaffName = this.filterNanme(this.$refs.personselect_jianhu.person)
			this.trainingDrill.dataSource = 'NEIOS_APP'+localStorage.getItem("currVersion")
			this.drill.dataSource = 'NEIOS_APP'+localStorage.getItem("currVersion")
			this.drillInfo.dataSource = 'NEIOS_APP'+localStorage.getItem("currVersion")
			this.trainingDrill.drill = this.drill
			this.trainingDrill.drillInfo = this.drillInfo

			if (this.workStatus == 10) {
				this.trainingDrill.status == ''
			}
			let param = {
				trainingDrill: this.trainingDrill,
				drill: this.drill,
				drillInfo: this.drillInfo,
				phenomenonList: this.phenomenon,
				activityAttachIds: this.activityAttachIds,
				currentUser: this.userInfo,
				trainingAttachList: this.trainingfileList
			}
			if (e == 'submit') {
				param.nextWorkStatus = this.nextWorkStatus
				param.workType = "0302"
				param.workId = this.workId
				this.submit(param)
				return
			}

			console.log(JSON.stringify(param))

			mui.neiosRequst.httpRequst('/app/tranEducation/saveDrill', param,
				function(data) {
					mui.toast('操作成功')
					let page = plus.webview.getWebviewById(
					"../sitOperation/terminalwork/terminalwork.html");
					let pageId = plus.webview.getWebviewById(page.id);
					let param = {}
					param.isRefresh = true
					mui.fire(pageId, 'isRefresh', param);
					setTimeout(function() {
						mui.back()
					}, 500);
				},
				function() {
					console.log("查询失败!");
				}
			);

		},
		//添加现象
		confirmKey() {
			if (this.phenomenonTxt == '') {
				mui.toast('请输入现象')
			}
			this.phenomenon.push({
				number: this.phenomenon.length + 1,
				phenomenon: this.phenomenonTxt,
				phenomenonNo: '现象' + (this.phenomenon.length + 1)

			})
			this.showAdd = false
		},
		//隐藏弹窗
		hideAdd() {
			this.showAdd = ''
		},
		//获取当前时间
		getDate() {
			var date = new Date()
			var year = date.getFullYear()
			var month = date.getMonth() + 1
			var day = date.getDate()
			var hour = date.getHours()
			var min = date.getMinutes()

			if (month.toString().length < 2) {
				month = '0' + month
			}
			if (day.toString().length < 2) {
				day = '0' + day
			}
			if (hour.toString().length < 2) {
				hour = '0' + hour
			}
			if (min.toString().length < 2) {
				min = '0' + min
			}
			this.nowDate = year + '-' + month + '-' + day + ' ' + hour + ':' + min
			this.getDetailbyworkId()
		},
		//通过workId查询
		getDetailbyworkId() {
			let that = this
			let param = {
				workId: this.workId
			}
			console.log("JSON:"+JSON.stringify(param))
			mui.neiosRequst.httpRequst('/app/tranEducation/getDrillByWorkId', param,
				function(data) {
				console.log("KKKKKKK:"+JSON.stringify(data))
					if (data.data.trainingDrillId != null) {
						that.mData = data.data;
						that.fileIds = data.data.fileIds
						that.fileIdsTraining = data.data.fileIdsTraining
						that.trainingDrill = data.data
						that.drill = data.data.drill == null ? {} : data.data.drill
						that.drillInfo = data.data.drillInfo == null ? {} : data.data.drillInfo
						if(null != data.data.drill){
							that.phenomenon = JSON.parse(data.data.drill.phenomenon)
						}
						that.getFileList()
						that.getFileList('train')
						that.changePerson()

					} else {
						that.getDetail()
					}
				},
				function() {
					console.log("查询失败!");
				}
			);
		},

		//获取文件信息
		getFileList(e) {
			var that = this
			if (e == 'train') {
				if(this.fileIdsTraining =='' || this.fileIdsTraining == null){
					return
				}
				var param = {
					fileIds: this.fileIdsTraining
				}

				mui.neiosRequst.httpRequst('/app/common/getFileList', param,
					function(data) {
						that.trainingfileList = data.data
					},
					function() {
						console.log("查询失败!");
					}

				);
				return
			}
			if(this.fileIds =='' || this.fileIds == null){
				return
			}
			var param = {
				fileIds: this.fileIds
			}

			mui.neiosRequst.httpRequst('/app/common/getFileList', param,
				function(data) {
					that.filesList = data.data
				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		//获取详情
		getDetail() {
			let that = this
			let param = {
				workId: "8454d55484974259976830a0584e3e42"
			}
			mui.neiosRequst.httpRequst('/app/currentEntry/neiosNetworkDevice/getTrainingByWorkId', param,
				function(data) {

					that.trainingDrill.hostStaffCode = that.userInfo.userId
					that.trainingDrill.hostStaffName = that.userInfo.name
					that.trainingDrill.hostStaffNameCode = '[' + that.userInfo.userId + ']' + that.userInfo
						.name
					that.trainingDrill.specialActiviteId = that.id
					that.trainingDrill.activityType = data.data.activityType
					that.trainingDrill.activityContent = data.data.activityContent
					that.trainingDrill = Object.assign({}, that.trainingDrill)
					that.drill.makeTime = that.nowDate

				},
				function() {
					console.log("查询失败!");
				}
			);
		},
		//返回上一页
		goBack() {
			mui.back()
		},
		//更多按钮
		showMore() {
			this.showMorebtn ? this.showMorebtn = false : this.showMorebtn = true
		},
		//阻止事件冒泡 
		clickStop() {

		},

		navTo(e) {
			mui.openWindow({
				url: e,
				id: e,
			});
		},
		// 上傳
		upload(e) {
			let that = this
			mui.neiosCommon.doUploads(function(ret) {
				if ("0" == ret.code) {
					console.log("成功：" + JSON.stringify(ret))
					if(e == 'fujian'){
						that.fileIds == "" ? that.fileIds += ret.data.fileId : that.fileIds += "," + ret
							.data.fileId;
					that.getFileList()	
					}
					else{
						that.fileIdsTraining == "" ? that.fileIdsTraining += ret.data.fileId : that.fileIdsTraining += "," + ret
							.data.fileId;
							that.getFileList('train')
					}
					
				} else {
					mui.toast('文件上传失败');
				}
			}, function(err) {
				mui.toast('文件上传失败');
			})
		},
		// 删除文件
		delDown(data) {
			let myFileIds = this.fileIds.split(',')
			myFileIds.splice(myFileIds.findIndex(item => item.fileId === data.fileId), 1)
			this.fileIds = myFileIds.join(',')
			console.log(this.fileIds)
			this.getFileds()
		},
		// 获取文件列表
		getFileds() {
			mui.neiosRequst.httpRequst('/app/common/getFileList', {
					fileIds: this.fileIds
				},
				(data) => {
					if (data.code == '0') {
						this.filesList = data.data
					} else {
						mui.toast("获取失败：" + data.msg);
					}
				},
				(data) => {
					mui.toast("退回失败：" + data.msg);
				}
			);
		},
		// 下载
		downLoad(data) {
			let url = "/app/common/downloadFile";
			let param = {};
			param.fileId = data.fileId;
			mui.neiosCommon.downLoadFile(param, function(ret) {
				mui.plusReady(function() {
					plus.nativeUI.closeWaiting();
				})
				//调用存储
				var callbackID = plus.bridge.callbackId(function(ret) {
					mui.toast(ret[0])
				}, function(err) {
					mui.toast('文件下载失败')
				});
				plus.bridge.execSync("FileHelper", "doFileSave", [callbackID, ret, data.fileName,
					"Argus3", "Argus4"
				])
			}, function(err) {
				mui.plusReady(function() {
					plus.nativeUI.closeWaiting();
				})
				mui.toast('文件下载失败')
			});
		},
	},

})
mui.init();
// $(function() {
// 	$("#dateSelect").click(function() {
// 		var dtPicker = new mui.DtPicker({
// 			type: 'datetime'
// 		});
// 		dtPicker.show(function(selectItems) {
// 			console.log(JSON.stringify(selectItems))
// 			$("#dateSelect").text(selectItems.text);
// 			projectVM.trainingDrill.begTime = selectItems.text

// 		})
// 	});
// 	$("#dateSelect1").click(function() {
// 		var dtPicker = new mui.DtPicker({
// 			type: 'datetime'
// 		});
// 		dtPicker.show(function(selectItems) {

// 		 $("#dateSelect1").text(selectItems.text);
// 			projectVM.trainingDrill.endTime = selectItems.text
// 		})
// 	});
// 	$("#dateSelect3").click(function() {
// 		var dtPicker = new mui.DtPicker({
// 			type: 'datetime'
// 		});
// 		dtPicker.show(function(selectItems) {

// 			$("#dateSelect3").text(selectItems.text);
// 			projectVM.drill.reviewTime = selectItems.text

// 		})
// 	});
// })
